package ut.res;
import java.util.HashMap;
import java.util.LinkedList;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.io.IOException;
public class Language{
	private static HashMap<Integer, Language> languageMap = null;
	private static LinkedList<Language> languageList = null;
	static{
		languageMap = new HashMap<Integer, Language>();
		languageList = new LinkedList<Language>();
		BufferedReader reader = null;
		try{
			reader = new BufferedReader(new InputStreamReader(new FileInputStream(System.getProperty("ut.resource") + "language.txt"), "utf-8"));
			String line;
			String[] data;
			Language language;
			while((line = reader.readLine()) != null){
				data = line.split("\t");
				language = new Language(Integer.parseInt(data[0]), data[1]);
				languageMap.put(language.id, language);
				languageList.add(language);
			}
		}catch(IOException e){
			e.printStackTrace();
		}finally{
			try{
				if(reader != null){
					reader.close();
				}
			}catch(IOException e){
				e.printStackTrace();
			}
		}
	}
	public static Language[] getLanguages(){
		return languageList.toArray(new Language[0]);
	}
	public static Language getLanguage(int id){
		return languageMap.get(id);
	}
	/* Instance Definition */
	public int id;
	public String title;
	public Language(int id, String title){
		this.id = id;
		this.title = title;
	}
}